//
//  RegisterThreeCollectionViewCell.m
//  MJApp
//
//  Created by 王亮 on 15/8/25.
//  Copyright (c) 2015年 王亮. All rights reserved.
//

#import "RegisterThreeCollectionViewCell.h"

@interface RegisterThreeCollectionViewCell ()

@property(nonatomic,strong)UITextField *passTextField;
@property(nonatomic,strong)UITextField *againTextField;
@property(nonatomic,strong)UITextField *nameTextField;

@end

@implementation RegisterThreeCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    CGFloat wide = 0.6 * CGRectGetWidth(self.frame);
    CGFloat centerX = CGRectGetWidth(self.frame) / 2;
    UITextField *passTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, wide, 30)];
    passTextField.placeholder = @"输入密码";
    passTextField.layer.cornerRadius = CGRectGetHeight(passTextField.frame) / 2;
    passTextField.center = CGPointMake(centerX, passTextField.center.y);
    passTextField.secureTextEntry = YES;
    passTextField.backgroundColor = [UIColor whiteColor];
    passTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    passTextField.leftViewMode = UITextFieldViewModeAlways;
    passTextField.font = [UIFont systemFontOfSize:15];
    [self addSubview:passTextField];
    self.passTextField = passTextField;
    
    UITextField *againNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(passTextField.frame) + 20, wide, 30)];
    againNameTextField.placeholder = @"再次输入密码";
    againNameTextField.secureTextEntry = YES;
    againNameTextField.layer.cornerRadius = CGRectGetHeight(againNameTextField.frame) / 2;
    againNameTextField.center = CGPointMake(centerX, againNameTextField.center.y);
    againNameTextField.backgroundColor = [UIColor whiteColor];
    againNameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    againNameTextField.leftViewMode = UITextFieldViewModeAlways;
    againNameTextField.font = [UIFont systemFontOfSize:15];
    [self addSubview:againNameTextField];
    self.againTextField = againNameTextField;
    
    UITextField *nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(againNameTextField.frame) + 20, wide, 30)];
    nameTextField.placeholder = @"个人昵称";
    nameTextField.layer.cornerRadius = CGRectGetHeight(nameTextField.frame) / 2;
    nameTextField.center = CGPointMake(centerX, nameTextField.center.y);
    nameTextField.backgroundColor = [UIColor whiteColor];
    nameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    nameTextField.leftViewMode = UITextFieldViewModeAlways;
    nameTextField.font = [UIFont systemFontOfSize:15];
    [self addSubview:nameTextField];
    self.nameTextField = nameTextField;
    
    
    
    UIButton *loginIn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(nameTextField.frame) + 20, wide, 30)];
    [loginIn setTitle:@"下一步" forState:UIControlStateNormal];
    loginIn.backgroundColor = RGB(228, 41, 9);
    loginIn.titleLabel.font = [UIFont systemFontOfSize:15];
    loginIn.center = CGPointMake(centerX, loginIn.center.y);
    loginIn.layer.cornerRadius = CGRectGetHeight(loginIn.frame) / 2;
    [loginIn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:loginIn];
}

- (void)login {
    
    if ([self.passTextField.text isEqualToString:@""]) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"密码为空"];
        return;
    }
    if (![self.passTextField.text isEqualToString:self.againTextField.text]) {
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"两次密码不一致"];
        return;
    }
    
    if ([self.delegate respondsToSelector:@selector(cellProtocolWithObj:withDic:)]) {
        NSDictionary *dic = @{@"index":@"2",@"pass":self.passTextField.text,@"name":self.nameTextField.text};
        [self.delegate cellProtocolWithObj:self withDic:dic];
    }
}


@end
